<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Questions | Show</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
    <link rel="shortcut icon" type="image/png" href="/static/img/favicon.png">
    <link rel="stylesheet" type="text/css" href="/static/main.css" />
  </head>
  <body>
    <nav class="navbar navbar-default navbar-static-top navbar-inverse">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">问答</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
          {{if not .answerUserId}}
          <li>
            <a href="/login?next=/chat"><i class="fa fa-commenting-o" aria-hidden="true"></i>&nbsp; 聊天</a>
          </li>
          {{else}}
          <li>
            <a href="/chat"><i class="fa fa-commenting-o" aria-hidden="true"></i>&nbsp; 聊天</a>
          </li>
          {{end}}
          <li>
            <a href="/categories"> 分类</a>
          </li>
          <li>
            <a href="/rank"> 用户榜</a>
          </li>
          <li>
            <a href="/"> 问题</a>
          </li>
          {{if .answerUserId}}
              {{if eq .answerUserId 1}}
              <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">欢迎 {{.user}} <span class="caret"></span></a>
                  <ul class="dropdown-menu">
                      <li><a href="/admin"><i class="fa fa-user"></i> Admin</a></li>
                      <li><a href="/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
                  </ul>
              </li>
              {{else}}
              <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">欢迎 {{.user}} <span class="caret"></span></a>
                  <ul class="dropdown-menu">
                      <li><a href="/profile/{{.answerUserId}}"><i class="fa fa-user"></i> Profile</a></li>
                      <li><a href="/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
                  </ul>
              </li>
              {{end}}
          {{else}}
          <li>
            <a href="/login"> 登录</a>
          </li>
          <li>
            <a href="/signup"> 注册</a>
          </li>
          {{end}}
        </ul>
      </div>
    </nav>



    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-lg-offset-2">

    <div class="list-group">
      <div class="list-group-item list-group-item-action flex-column align-items-start">
        <div class="d-flex w-100 justify-content-between">
          <h4 class="mb-1"><b>{{.question.Title}}</b>
            <small>asked {{.question.CreatedAt.Format "2006-01-02 15:04"}} by <b><a href='/profile/{{.question.User.Id}}'>{{.question.User.Username}}</a></b>
              </b></small></h4>
          <hr>
          <p class="mb-1">{{.question.Body}}</p><br>
          {{range .tags}}
          <a href="/tags/{{.Name}}" class="btn btn-xs btn-primary">{{.Name}}</a>
          {{end}}
          {{if not .user}}
          <a href="/login?next=/show/{{.question.Id}}" class="btn btn-default pull-right" style="color:#33cc33;" value="submit"><i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.question.Likes}} &ensp;</i></a><br><br>
          {{else}}
          <form action="/questionlikes" method="post">
              <input type="hidden" name="id" value="{{.question.Id}}">
              <button class="btn btn-default pull-right" style="color:#33cc33;" value="submit"><i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.question.Likes}} &ensp;</i></button><br><br>
          </form>
          {{end}}
        </div>
      </div>
    </div>
    {{if .user}}
    <form action="/saveanswer" method="post">
        <div class="form-group">
            <input type="hidden" class="form-control" name="user" value="{{ .answerUserId }}"><br>
            <input type="hidden" class="form-control" name="id" value="{{ .question.Id }}"><br>
            <textarea class="form-control" name="body" rows="8" class="form-control" placeholder="Add body" required></textarea><br>
            <button type="submit" class="btn btn-success">
                <i class="fa fa-plus"></i> Submit
            </button><br><br><br>
        </div>
    </form>
    {{else}}
    <h4 class="pull-left">{{.count}} answers</h4>
    <a href="/login?next=/show/{{.question.Id}}" class="btn btn-success pull-right">
        <i class="fa fa-plus"></i> Answer
    </a><br><br><br>
    {{end}}

      {{$var := .question.Id}}
            {{if not .user}}
            {{ range .answers }}
            <div class="list-group-item list-group-item-action flex-column align-items-start">
                <div class="d-flex w-100 justify-content-between">
                    <div class="d-flex w-100 justify-content-between">
                        <h4 class="mb-1">
                            <small>Answered {{.CreatedAt.Format "2006-01-02 15:04"}} by <b><a href="/profile/{{.User.Id}}">{{ .User.Username }}</a></b>
                                {{if .IsAcceptedAnswer}}
                                <span class="badge pull-right">Accepted answer</span>
                                <br>
                                {{end}}
                                </b></small></h4>
                        <hr>
                        <h4 class="mb-1">{{ .Body }}</h4><br>
                        <div class="row">
                              <div class="col-md-1 col-sm-1 col-xs-1">
                                  <a href="/login?next=/show/{{$var}}" class="btn btn-default pull-left" style="color:#33cc33;">
                                      <i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.Likes}} &ensp;</i>
                                  </a>
                              </div>
                              <div class="col-md-1 col-sm-1 col-xs-1">
                                  <a href="/login?next=/show/{{$var}}" class="btn btn-default pull-left" style="color:#ff6666;">
                                      <i class="fa fa-thumbs-down" aria-hidden="true" title="Disike"> {{.DisLikes }}&ensp;</i>
                                  </a><br>
                              </div>
                          </div>
                    </div>
                </div>
            </div>
            <br>
            {{end}}
            {{else}}

                {{if eq .question.User.Username .user}}

                {{if and (eq .question.User.Username .user) (.question.AcceptedAnswer)}}

                    {{ range .answers }}
                    <div class="list-group-item list-group-item-action flex-column align-items-start">
                        <div class="d-flex w-100 justify-content-between">
                            <div class="d-flex w-100 justify-content-between">
                                <h4 class="mb-1">
                                    <small>Answered {{.CreatedAt.Format "2006-01-02 15:04"}} by <b><a href="/profile/{{.User.Id}}">{{ .User.Username }}</a></b>
                                        {{if .IsAcceptedAnswer}}
                                        <span class="badge pull-right">Accepted answer</span>
                                        <br>
                                        {{end}}
                                        </b></small></h4>
                                <hr>
                                <h4 class="mb-1">{{ .Body }}</h4><br>
                                <div class="row">
                                    <div class="col-md-1 col-sm-1 col-xs-1">
                                        <form action="/answerlikes" method="post">
                                            <input type="hidden" name="aid" value="{{.Id}}">
                                            <input type="hidden" name="qid" value="{{$var}}">
                                            <button class="btn btn-default pull-left" style="color:#33cc33;" value="submit"><i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.Likes}} &ensp;</i></a></button><br>
                                        </form>
                                    </div>
                                    <div class="col-md-1 col-sm-1 col-xs-1">

                                        <form action="/answerdislikes" method="post">
                                            <input type="hidden" name="aid" value="{{.Id}}">
                                            <input type="hidden" name="qid" value="{{$var}}">
                                            <button class="btn btn-default pull-left" style="color:#ff6666;" value="submit"><i class="fa fa-thumbs-down" aria-hidden="true" title="Disike"> {{.DisLikes}} &ensp;</i></a></button><br>
                                        </form>
                                        <br>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <br>
                    {{end}}

                {{else}}
                    {{ range .answers }}
                    <div class="list-group-item list-group-item-action flex-column align-items-start">
                        <div class="d-flex w-100 justify-content-between">
                            <div class="d-flex w-100 justify-content-between">
                                <h4 class="mb-1">
                                    <small>Answered {{.CreatedAt.Format "2006-01-02 15:04"}} by <b><a href="/profile/{{.User.Id}}">{{ .User.Username }}</a></b>
                                        </b></small></h4>
                                <hr>
                                <h4 class="mb-1">{{ .Body }}</h4><br>
                                <form action="/acceptanswer" method="post">
                                    <input type="hidden" name="aid" value="{{.Id}}">
                                    <input type="hidden" name="qid" value="{{$var}}">
                                    <button class="btn btn-primary pull-right" value="submit">Accept answer</button>
                                </form>
                                <div class="row">
                                    <div class="col-md-1 col-sm-1 col-xs-1">
                                        <form action="/answerlikes" method="post">
                                            <input type="hidden" name="aid" value="{{.Id}}">
                                            <input type="hidden" name="qid" value="{{$var}}">
                                            <button class="btn btn-default pull-left" style="color:#33cc33;" value="submit"><i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.Likes}} &ensp;</i></a></button><br>
                                        </form>
                                    </div>
                                    <div class="col-md-1 col-sm-1 col-xs-1">

                                        <form action="/answerdislikes" method="post">
                                            <input type="hidden" name="aid" value="{{.Id}}">
                                            <input type="hidden" name="qid" value="{{$var}}">
                                            <button class="btn btn-default pull-left" style="color:#ff6666;" value="submit"><i class="fa fa-thumbs-down" aria-hidden="true" title="Disike"> {{.DisLikes}} &ensp;</i></a></button><br>
                                        </form>
                                        <br>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <br>
                    {{end}}

                    {{end}}
                    {{else}}
                        {{ range .answers }}
                        <div class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <div class="d-flex w-100 justify-content-between">
                                    <h4 class="mb-1">
                                        <small>Answered {{.CreatedAt.Format "2006-01-02 15:04"}} by <b><a href="/profile/{{.User.Id}}">{{ .User.Username }}</a></b>
                                            {{if .IsAcceptedAnswer}}
                                            <span class="badge pull-right">Accepted answer</span>
                                            <br>
                                            {{end}}
                                            </b></small></h4>
                                    <hr>
                                    <h4 class="mb-1">{{ .Body }}</h4><br>
                                    <div class="row">
                                        <div class="col-md-1 col-sm-1 col-xs-1">
                                            <form action="/answerlikes" method="post">
                                                <input type="hidden" name="aid" value="{{.Id}}">
                                                <input type="hidden" name="qid" value="{{$var}}">
                                                <button class="btn btn-default pull-left" style="color:#33cc33;" value="submit"><i class="fa fa-thumbs-up" aria-hidden="true" title="Like"> {{.Likes}} &ensp;</i></a></button><br>
                                            </form>
                                        </div>
                                        <div class="col-md-1 col-sm-1 col-xs-1">

                                            <form action="/answerdislikes" method="post">
                                                <input type="hidden" name="aid" value="{{.Id}}">
                                                <input type="hidden" name="qid" value="{{$var}}">
                                                <button class="btn btn-default pull-left" style="color:#ff6666;" value="submit"><i class="fa fa-thumbs-down" aria-hidden="true" title="Disike"> {{.DisLikes}} &ensp;</i></a></button><br>
                                            </form>
                                            <br>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <br>
                        {{end}}
                        {{end}}
                        {{end}}


        </div>
      </div>
    </div>

    </div>

  </body>
</html>
